<?php
	class Product_sizes_model extends CI_Model {
	    
    var $id;
	var $product_id;    
	var $size;
	var $code;
	var $quantity;
    var $created_at;
    var $updated_at;

    function __construct()
    {
        // Call the Model constructor
        parent::__construct();
    }

    // load all Storage
    function loadAll()
    {
        $query = $this->db->get('product_sizes');
        return $query->result();
    }    

    function getEntry($con,$id)
    {
        if($con == 'id')
        {
            $query = $this->db->get_where('product_sizes', array('id' => $id));    
        }
        else if($con == 'code')
        {
            $query = $this->db->get_where('product_sizes', array('code' => $id));
        }
        
        return $query->row();
    }

    function getProduct($cond)
    {
        $this->db->select('*');
        $this->db->from('product_sizes');

        foreach ($cond as $key => $value) 
        {
            $this->db->where("$key",$value);
        }

        $query = $this->db->get();
        
        return $query->result();
    }
    

    function getInfoSizeProduct($product_id = false)
    {
        $query = $this->db->get_where('product_sizes', array('product_id' => $product_id));
        return $query->result();
    }

    function updateQuantity($code,$type)
    {
        $query = $this->db->get_where('product_sizes', array('code' => $code));
        $row = $query->row();

        if($type == 'decrease')
        {
            $quantity = $row->quantity - 1;           
        }
        else
        {
            $quantity = $row->quantity + 1;       
        }
        
        
        $this->db->where('code',$code);
        $this->db->update('product_sizes',array('quantity' => $quantity));
    }

    function insert($data)
    {
        $this->db->insert('product_sizes', $data);
    }

}